package com.patrol.inspection.Controller;

import com.patrol.inspection.Entity.testObject;
import com.patrol.inspection.Utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/test")
public class KafkaController {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    @RequestMapping("/get")
    public String get(){
        testObject io = testObject.builder()
                .gsiId(1L)
                .stolenId(1L)
                .goodsId(1L)
                .testDesc("kafka Demo")
                .similarity(-1.0)
                .build();

        sendMessage("npl", JsonUtils.convertObjToJSON(io));
        System.out.println(JsonUtils.convertObjToJSON(io));
        return "test";
    }



    public void sendMessage(String topic, String message) {
        kafkaTemplate.send(topic, UUID.randomUUID().toString(),message);
    }
}
